﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace Game_Engine
{
    public class CheckBox : GUIElement
    {
        public Texture2D Check { get; set; }
        public Color CheckColor { get; set; }
        public bool Checked { get; set; }

        public CheckBox(Texture2D texture, Texture2D check, Rectangle rectangle, String text, Color background, Color textColor, Color checkColor)
        {
            Texture = texture;
            BackgroundColor = background;
            Bounds = rectangle;
            Text = text;
            TextColor = textColor;

            Check = check;
            CheckColor = checkColor;
            Checked = false;
        }

        public override void Update()
        {
            if ((InputManager.KeyPressed(Keys.Enter) && Selected) || (InputManager.MousePressed(0) && Bounds.Contains(InputManager.GetMousePosition())))
            {
                Checked = !Checked;
                OnAction();
            }
            base.Update();
        }

        public override void Draw(SpriteBatch spriteBatch, SpriteFont font)
        {
            base.Draw(spriteBatch, font);
            int width = Math.Min(Bounds.Width, Bounds.Height);
            spriteBatch.Draw(Check, new Rectangle(Bounds.X, Bounds.Y, width, width),
                Checked ? CheckColor : Selected ? BackgroundColor : Color.White);
            spriteBatch.DrawString(font, Text, new Vector2(Bounds.X + 2 * width, Bounds.Y), TextColor);
        }
    }
}
